*Replication codes for "Job Satisfaction and Citizen Satisfaction with Street-level Bureaucrats: Is There a Satisfaction Mirror?"
*Authors: Nicolai Petrovsky, Ge Xin, Jinhai Yu
*Journal: JPART
*Last updated: 03/21/2022

* Please note, the following ado files will have to be installed: 
* asdoc, medeff, medsens, outreg2
* --> search the help function to see if you already have them installed

* Begin a log
log using JPARTsatismirror.smcl, replace

* Set Stata version for reproducibility in the future
version 16.1

* Open the data
use SatisMirrorData,clear

* Save a workfile to protect the original data
save workfile, replace


*** PART ONE: Variables construction

** Villager control variables
gen v_female=(VLGRGENDER==2)
gen v_edu=VLGREDU
gen v_edu2=(v_edu==2)
gen v_edu3=(v_edu==3)
gen v_edu4=(v_edu==4)
gen v_income=VLGRINC
gen v_income2=(v_income==2)
gen v_income3=(v_income==3)
gen v_income4=(v_income==4)
gen v_family_size=FAMSIZE
gen v_residence_time=LIVYRS
gen v_counter= (ENCOUNTER==1)
gen v_meet_times= MEETTIME
gen villager_id=VillagerID
gen v_age=VLGRAGE
gen v_age2=(v_age==2)
gen v_age3=(v_age==3)
gen v_age4=(v_age==4)


** Village leader control variables
gen leader_age=LDAGE
gen leader_age2=(leader_age==2)
gen leader_age3=(leader_age==3)
gen leader_age4=(leader_age==4)
gen leader_female=(LGENDER==2)
gen leader_income=LDINCOME
gen leader_income3=(leader_income==3)
gen leader_income4=(leader_income==4)
gen leader_edu=LDEDU
gen leader_edu2=(leader_edu==2)
gen leader_edu3=(leader_edu==3)
gen leader_edu4=(leader_edu==4)
gen leader_work_exp=WORKYRS
gen leader_tenure=POSTYRS


** Village control (village rating)
gen village_type=VLGCAT
gen village_id=VillageID


**** PART TWO: Main Results

*Table 3

* Panel-A measure job satisfaction with multiple indicators
alpha WORKCON-FRIEND
factor WORKCON-FRIEND,pcf
rotate
rotate, blanks(.6)
predict job_satis_external job_satis_internal

* Panel-B measure perceived job performance of village leaders by villagers
alpha EXPLAINA-FAIRNESS
factor EXPLAINA-FAIRNESS,pcf
predict perceived_performance

* measure expectation gap**** to be checked
egen perform_std=std(perceived_performance)
egen expect_std=std(expectation)
gen expect_gap=abs(expect_std-perform_std)


* Table 4: Descriptive Statistics
asdoc summarize citizen_satis overall_job_satis job_satis_external job_satis_internal perceived_performance EXPLAINA-FAIRNESS WORKCON-FRIEND expect_gap v_age2 v_age3 v_age4 v_female v_edu2 v_edu3 v_edu4 v_income2 v_income3 v_income4 v_family_size v_residence_time v_meet_times v_counter r_village_type ///
    leader_age2 leader_age3 leader_age4 leader_female leader_income3 leader_income4 leader_edu2 leader_edu3 leader_edu4 leader_work_exp leader_tenure


* Table 5-Model 1: overall job satisfaction+perceived performance
sem(overall_job_satis leader_age2 leader_age3 leader_age4 leader_female leader_income3 leader_income4 leader_edu2 leader_edu3 leader_edu4 leader_tenure v_age2 v_age3 v_age4 v_female v_edu2 v_edu3 v_edu4 v_income2 v_income3 v_income4 v_family_size v_residence_time -> perceived_performance) ///
   (perceived_performance overall_job_satis expect_gap leader_age2 leader_age3 leader_age4 leader_female leader_income3 leader_income4 leader_edu2 leader_edu3 leader_edu4 leader_tenure v_age2 v_age3 v_age4 v_female v_edu2 v_edu3 v_edu4 v_income2 v_income3 v_income4 v_family_size v_residence_time -> citizen_satis),vce(cluster village_id)
estat eqgof
estat teffects
estat mindices
sem, standardize
outreg2 using satismirror1.xls, stats(coef se pval) dec(3) paren(se) bracket(pval)

* Table 5-Model 2: two-factor job satisfaction+perceived performance 
sem(job_satis_external job_satis_internal leader_age2 leader_age3 leader_age4 leader_female leader_income3 leader_income4 leader_edu2 leader_edu3 leader_edu4 leader_tenure v_age2 v_age3 v_age4 v_female v_edu2 v_edu3 v_edu4 v_income2 v_income3 v_income4 v_family_size v_residence_time -> perceived_performance) ///
   (perceived_performance job_satis_external job_satis_internal expect_gap leader_age2 leader_age3 leader_age4 leader_female leader_income3 leader_income4 leader_edu2 leader_edu3 leader_edu4 leader_tenure v_age2 v_age3 v_age4 v_female v_edu2 v_edu3 v_edu4 v_income2 v_income3 v_income4 v_family_size v_residence_time -> citizen_satis),vce(cluster village_id)
estat eqgof
estat teffects
estat mindices
sem, standardize
outreg2 using satismirror1.xls, stats(coef se pval) dec(3) paren(se) bracket(pval) 


* Table 6-Model 1: overall job satisfaction+objective performance
sem(overall_job_satis leader_age2 leader_age3 leader_age4 leader_female leader_income3 leader_income4 leader_edu2 leader_edu3 leader_edu4 leader_tenure v_age2 v_age3 v_age4 v_female v_edu2 v_edu3 v_edu4 v_income2 v_income3 v_income4 v_family_size v_residence_time-> r_village_type) ///
   (r_village_type overall_job_satis expect_gap leader_age2 leader_age3 leader_age4 leader_female leader_income3 leader_income4 leader_edu2 leader_edu3 leader_edu4 leader_tenure v_age2 v_age3 v_age4 v_female v_edu2 v_edu3 v_edu4 v_income2 v_income3 v_income4 v_family_size v_residence_time-> citizen_satis),vce(cluster village_id) 
outreg2 using satismirror2.xls, stats(coef se pval) dec(3) paren(se) bracket(pval) 

* Table 6-Model 2: two-factor job satisfaction+objective performance
sem(job_satis_external job_satis_internal leader_female leader_age2 leader_age3 leader_age4 leader_income3 leader_income4 leader_edu2 leader_edu3 leader_edu4 leader_tenure v_female  v_age2 v_age3 v_age4 v_edu2 v_edu3 v_edu4 v_income2 v_income3 v_income4 v_family_size v_residence_time -> r_village_type) ///
   (r_village_type job_satis_external job_satis_internal expect_gap leader_female leader_age2 leader_age3 leader_age4 leader_income3 leader_income4 leader_edu2 leader_edu3 leader_edu4 leader_tenure v_female  v_age2 v_age3 v_age4 v_edu2 v_edu3 v_edu4 v_income2 v_income3 v_income4 v_family_size v_residence_time-> citizen_satis),vce(cluster village_id)  
outreg2 using satismirror2.xls, stats(coef se pval) dec(3) paren(se) bracket(pval) 


* Table 7: Causal Mediation Analysis
medeff(regress perceived_performance overall_job_satis leader_age2  leader_age4 leader_female leader_income3 leader_income4 leader_edu2 leader_edu3 leader_edu4 leader_tenure v_age2 v_age3 v_age4 v_female v_edu2 v_edu3 v_edu4 v_income2 v_income3 v_income4 v_family_size v_residence_time) ///
      (regress citizen_satis perceived_performance overall_job_satis expect_gap leader_age2  leader_age4 leader_female leader_income3 leader_income4 leader_edu2 leader_edu3 leader_edu4  leader_tenure v_age2 v_age3 v_age4 v_female v_edu2 v_edu3 v_edu4 v_income2 v_income3 v_income4 v_family_size v_residence_time), ///
      med(perceived_performance) treat(overall_job_satis) vce(cluster village_id)
medsens(regress perceived_performance overall_job_satis leader_female leader_age2  leader_age4 leader_edu2 leader_edu3 leader_edu4 leader_income3 leader_income4 leader_tenure v_age2 v_age3 v_age4 v_female v_edu2 v_edu3 v_edu4 v_income2 v_income3 v_income4 v_family_size v_residence_time) ///
       (regress citizen_satis perceived_performance overall_job_satis expect_gap leader_female leader_age2  leader_age4 leader_edu2 leader_edu3 leader_edu4 leader_income3 leader_income4 leader_tenure v_age2 v_age3 v_age4 v_female v_edu2 v_edu3 v_edu4 v_income2 v_income3 v_income4 v_family_size v_residence_time), med(perceived_performance) treat(overall_job_satis)   
twoway rarea _med_updelta0 _med_lodelta0 _med_rho, bcolor(gs14) || line _med_delta0 _med_rho, lcolor(black) ytitle("AME") title("AME({&rho})") xtitle("Sensitivity parameter: {&rho}") legend(on) scheme(sj)
	
	
*** PART THREE: Robustness Checks


* Table A6: Causal Mediation Analysis for internal job satistication
medeff(regress perceived_performance job_satis_internal job_satis_external leader_age2 leader_age3 leader_age4 leader_female leader_income3 leader_income4 leader_edu2 leader_edu3 leader_edu4 leader_tenure v_age2 v_age3 v_age4 v_female v_edu2 v_edu3 v_edu4 v_income2 v_income3 v_income4 v_family_size v_residence_time) ///
      (regress citizen_satis perceived_performance job_satis_internal job_satis_external expect_gap leader_age2 leader_age3 leader_age4 leader_female leader_income3 leader_income4 leader_edu2 leader_edu3 leader_edu4  leader_tenure v_age2 v_age3 v_age4 v_female v_edu2 v_edu3 v_edu4 v_income2 v_income3 v_income4 v_family_size v_residence_time), ///
      med(perceived_performance) treat(job_satis_internal) vce(cluster village_id)
	  
	  
* Table A7: Causal Mediation Analysis for external job satisfaction
medeff(regress perceived_performance job_satis_external job_satis_internal leader_age2 leader_age4 leader_female leader_income3 leader_income4 leader_edu2 leader_edu3 leader_edu4 leader_tenure v_age2 v_age3 v_age4 v_female v_edu2 v_edu3 v_edu4 v_income2 v_income3 v_income4 v_family_size v_residence_time) ///
      (regress citizen_satis perceived_performance job_satis_external job_satis_internal expect_gap leader_age2 leader_age4 leader_female leader_income3 leader_income4 leader_edu2 leader_edu3 leader_edu4  leader_tenure v_age2 v_age3 v_age4 v_female v_edu2 v_edu3 v_edu4 v_income2 v_income3 v_income4 v_family_size v_residence_time), ///
      med(perceived_performance) treat(job_satis_external) vce(cluster village_id)


** Setting up for the Aggregated Models
bysort village_id: egen a_citizen_satis=mean(citizen_satis)
bysort village_id: egen a_perceived_performance=mean(perceived_performance)

bysort village_id: egen a_v_age2=mean(v_age2)
bysort village_id: egen a_v_age3=mean(v_age3)
bysort village_id: egen a_v_age4=mean(v_age4)

bysort village_id: egen a_v_female=mean(v_female)

bysort village_id: egen a_v_edu2=mean(v_edu2)
bysort village_id: egen a_v_edu3=mean(v_edu3)
bysort village_id: egen a_v_edu4=mean(v_edu4)

bysort village_id: egen a_v_income2=mean(v_income2)
bysort village_id: egen a_v_income3=mean(v_income3)
bysort village_id: egen a_v_income4=mean(v_income4)

bysort village_id: egen a_v_family_size=mean(v_family_size)
bysort village_id: egen a_v_residence_time =mean(v_residence_time)
bysort village_id: egen a_v_counter=mean(v_counter)
bysort village_id: egen a_v_meet_times=mean(v_meet_times)
bysort village_id: egen a_expect_gap=mean(expect_gap)

egen tag=tag(village_id)


* Table A11-Aggregated Model 1
sem(overall_job_satis leader_age2 leader_age3 leader_age4 leader_female leader_income3 leader_income4 leader_edu2 leader_edu3 leader_edu4 leader_tenure a_v_age2 a_v_age3 a_v_age4 a_v_female a_v_edu2 a_v_edu3 a_v_edu4 a_v_family_size ->a_perceived_performance) ///
   (a_perceived_performance overall_job_satis a_expect_gap leader_female leader_age2 leader_age3 leader_age4 leader_income3 leader_income4 leader_edu2 leader_edu3 leader_edu4 leader_tenure a_v_age2 a_v_age3 a_v_age4 a_v_female a_v_edu2 a_v_edu3 a_v_edu4  a_v_family_size ->a_citizen_satis) if tag==1  
outreg2 using satismirrorA1.xls, stats(coef se pval) dec(3) paren(se) bracket(pval) 
      
* Table A11-Aggregated Model 2
sem(job_satis_external job_satis_internal leader_female leader_age2 leader_age3 leader_age4 leader_income3 leader_income4 leader_edu2 leader_edu3 leader_edu4 leader_tenure a_v_age2 a_v_age3 a_v_age4 a_v_female a_v_edu2 a_v_edu3 a_v_edu4  a_v_family_size  ->a_perceived_performance) ///
   (a_perceived_performance job_satis_external job_satis_internal a_expect_gap leader_age2 leader_age3 leader_age4 leader_female leader_age2 leader_age3 leader_age4 leader_income3 leader_income4 leader_edu2 leader_edu3 leader_edu4 leader_tenure a_v_age2 a_v_age3 a_v_age4 a_v_female a_v_edu2 a_v_edu3 a_v_edu4 a_v_family_size ->a_citizen_satis) if tag==1
outreg2 using satismirrorA1.xls, stats(coef se pval) dec(3) paren(se) bracket(pval) 


* Table A12-Robust Checks for UPDATED Aggregated Model 1
sem(overall_job_satis leader_age2 leader_age3 leader_age4 leader_female leader_income3 leader_income4 leader_edu2 leader_edu3 leader_edu4 leader_tenure a_v_age2 a_v_age3 a_v_age4 a_v_female a_v_edu2 a_v_edu3 a_v_edu4 a_v_family_size a_v_income2 a_v_income3 a_v_income4 a_v_residence_time ->a_perceived_performance) ///
   (a_perceived_performance overall_job_satis a_expect_gap leader_female leader_age2 leader_age3 leader_age4 leader_income3 leader_income4 leader_edu2 leader_edu3 leader_edu4 leader_tenure a_v_age2 a_v_age3 a_v_age4 a_v_female a_v_edu2 a_v_edu3 a_v_edu4 a_v_family_size a_v_income2 a_v_income3 a_v_income4 a_v_residence_time->a_citizen_satis) if tag==1
   
outreg2 using satismirrorA2.xls, stats(coef se pval) dec(3) paren(se) bracket(pval) 
   
* Table A12-Robust Checks for UPDATED Aggregated Model 2
sem(job_satis_external job_satis_internal leader_female leader_age2 leader_age3 leader_age4 leader_income3 leader_income4 leader_edu2 leader_edu3 leader_edu4 leader_tenure a_v_age2 a_v_age3 a_v_age4 a_v_female a_v_edu2 a_v_edu3 a_v_edu4  a_v_family_size a_v_income2 a_v_income3 a_v_income4 a_v_residence_time ->a_perceived_performance) ///
   (a_perceived_performance job_satis_external job_satis_internal a_expect_gap leader_age2 leader_age3 leader_age4 leader_female leader_age2 leader_age3 leader_age4 leader_income3 leader_income4 leader_edu2 leader_edu3 leader_edu4 leader_tenure a_v_age2 a_v_age3 a_v_age4 a_v_female a_v_edu2 a_v_edu3 a_v_edu4 a_v_family_size a_v_income2 a_v_income3 a_v_income4 a_v_residence_time ->a_citizen_satis) if tag==1
   
outreg2 using satismirrorA2.xls, stats(coef se pval) dec(3) paren(se) bracket(pval) 


* Table A13 Robustness Check for Model 1 and Model 2: exclude those with zero encounters in the past week
* not control for v_edu4 because no obs in the subsample
sum v_edu2 v_edu3 v_edu4 if v_counter !=0

sem(overall_job_satis leader_age2 leader_age3 leader_age4 leader_female leader_income3 leader_income4 leader_edu2 leader_edu3 leader_edu4 leader_tenure v_age2 v_age3 v_age4 v_female v_edu2 v_edu3 v_income2 v_income3 v_income4 v_family_size v_residence_time -> perceived_performance) ///
   (perceived_performance overall_job_satis expect_gap leader_age2 leader_age3 leader_age4 leader_female leader_income3 leader_income4 leader_edu2 leader_edu3 leader_edu4 leader_tenure v_age2 v_age3 v_age4 v_female v_edu2 v_edu3 v_income2 v_income3 v_income4 v_family_size v_residence_time -> citizen_satis),vce(cluster village_id), if v_counter !=0
estat eqgof
estat teffects
estat mindices
sem, standardize
outreg2 using satismirrorA3.xls, stats(coef se pval) dec(3) paren(se) bracket(pval) replace


sem(job_satis_external job_satis_internal leader_age2 leader_age3 leader_age4 leader_female leader_income3 leader_income4 leader_edu2 leader_edu3 leader_edu4 leader_tenure v_age2 v_age3 v_age4 v_female v_edu2 v_edu3 v_income2 v_income3 v_income4 v_family_size v_residence_time -> perceived_performance) ///
   (perceived_performance job_satis_external job_satis_internal expect_gap leader_age2 leader_age3 leader_age4 leader_female leader_income3 leader_income4 leader_edu2 leader_edu3 leader_edu4 leader_tenure v_age2 v_age3 v_age4 v_female v_edu2 v_edu3 v_income2 v_income3 v_income4 v_family_size v_residence_time -> citizen_satis),vce(cluster village_id), if v_counter !=0
estat eqgof
estat teffects
estat mindices
sem, standardize
outreg2 using satismirrorA3.xls, stats(coef se pval) dec(3) paren(se) bracket(pval) 

save,replace


* Table 10 List Experiment on citizen satisfaction

* Open the data
use ListExpData,clear

gen female=(gender==2)

* Panel A 
tab num_sentence if treated==0
tab num_sentence if treated==1

* Panel B
ttest num_sentence,by(treated) unequal
ttest age,by(treated) unequal
ttest female,by(treated) unequal
ttest edu,by(treated) unequal
ttest income,by(treated) unequal
ttest fam_size,by(treated) unequal
ttest residence_yrs,by(treated) unequal


* Close the log file
log close
exit
